import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
import common from './common'
import * as hooks from './hooks'

Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  routes: [
    ...common,
    {
      path: '*',
      component: () => import('@/views/notfound')
    }
  ]
})

// 批处理前置守卫
Object.keys(hooks).forEach(name => {
  router.beforeEach(hooks[name](store, router))
})

export default router
